import { createLogger, format, transports } from 'winston';
import * as DailyRotateFile from 'winston-daily-rotate-file';
import * as chalk from 'chalk';
const logFormat = format.combine(
    // format.colorize(),
    format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }),
    format.printf(({ timestamp, level, message }) => `${ chalk.greenBright(timestamp)} ${chalk.yellow(level)}: ${chalk.green(message)}`)
);
const fileFormat = format.combine(
    format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }),
    format.printf(({ timestamp, level, message }) => `${timestamp} ${level}: ${message}`)
); 
const logger = createLogger({
    level: 'info',
    format: logFormat,
    // defaultMeta: { service: 'user-service' },
    transports: [
        // new transports.Console(),
        new DailyRotateFile({
            format: fileFormat,
            filename: 'logs/app-%DATE%.log',
            datePattern: 'YYYY-MM-DD',
            maxSize: '20MB',
            maxFiles: '14d',
            zippedArchive: true,
        }),
    ],
    exceptionHandlers: [
        new transports.File({ 
            dirname: 'logs',
            filename: 'exceptions.log' 
        })
    ]
});

if (process.env.NODE_ENV !== 'production') {
    logger.add(new transports.Console({
        // format: format.simple(),
    }));
}

// console.log('logger...................: ');

export default logger;